package com.project.dao.impl;

import java.sql.*;

public class BaseDao {
    /**
     * DAO的父类
     */

    /**
     * 连接
     */
    protected Connection con;
    /**
     * SQL语句执行对象
     */
    protected PreparedStatement ps;
    /**
     * 结果集
     */
    protected ResultSet re;

    /**
     * 建立链接
     */
    public void setConnection() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:12345/test?characterEncoding=Utf-8",
                    "root", "lovo");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 关闭流操作
     */
    public void closeConnection() {
        try {
            if (re != null) {
                re.close();
            }
            if (ps != null) {
                ps.close();
            }
            if (con != null) {
                con.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }


}
